home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Science
/
RLaB
/
rlib
/
cumprod.r
< prev
next >
Wrap
Text File
|
1994-04-25
|
725b
|
42 lines
//-------------------------------------------------------------------//
// Syntax: cumprod ( X )
// Description:
// Compute the cumulative product of a vector or a matrix.
// See Also: prod
//-------------------------------------------------------------------//
cumprod = function ( x )
{
local (i, j, m, n, new);
m = x.nr;
n = x.nc;
new = zeros (m, n);
if (min ([m, n]) == 1)
{
// cumsum on a vector
new[1] = x[1];
for (i in 2:max ([m,n]))
{
new[i] = x[i] * new[i-1];
}
else
// cumsum on the columns of a matrix
for (i in 1:n)
{
new[1;i] = x[1;i];
for (j in 2:m)
{
new[j;i] = x[j;i] * new[j-1;i];
}
}
}
return (new);
};